﻿import http from '@/utils/http'
import { IsNull } from '@/utils/utils'

export default {
  //
  // 后台获取应用信息
  //
  // 获取所有应用信息
  getListMyActiveApps(searchkey) {
    return http.GET(Global.addressip + `/api/App/GetListMyActiveApps/${searchkey || ''}`)
  },
  // 获取我的应用
  getListMyAllApps() {
    return http.GET(Global.addressip + `/api/App/GetListMyAllApps`)
  },
  // 获取已禁用应用
  getListMyInactiveApps() {
    return http.GET(Global.addressip + `/api/App/GetListMyInactiveApps`)
  },
  // 获取基础管理app信息
  getAppInfoById(objectId) {
    return http.GET(Global.addressip + `/api/App/GetAppInfoById/${objectId}`)
  },
  // 获取基础管理app设置信息
  getAppManagerById(objectId) {
    return http.GET(Global.addressip + `/api/App/GetAppManagerById/${objectId}`)
  },
  // 获取系统角色
  getAppRoleList(appCode) {
    return http.GET(Global.addressip + `/api/Organization/GetAppRoleList/${appCode}`)
  },
  // 获取功能权限列表信息
  getAppActions(appCode) {
    return http.GET(Global.addressip + `/api/App/GetAppActions/${appCode}`)
  },
  // 获取app权限
  getAppPermission(appCode, objectId) {
    return http.GET(Global.addressip + `/api/App/GetAppPermission/${appCode}/${objectId}`)
  },
  // 获取权限人员列表
  getRoleUserList(param) {
    return http.POST(Global.addressip + `/api/Organization/getRoleUserList`, param)
  },
  updateApp(isUpload, param) {
    return http.POST(Global.addressip + `/api/app/UpdateApp/${isUpload}`, param)
  },
  addApp(param) {
    return http.POST(Global.addressip + `/api/app/AddApp`, param)
  },
  deleteApp(objectId) {
    return http.GET(Global.addressip + `/api/app/DeleteApp/${objectId}`)
  },
  addAppOrg(param) {
    return http.POST(Global.addressip + `/api/Organization/AddAppOrgRole`, param)
  },
  checkAppOrg(name) {
    return http.GET(Global.addressip + `/api/Organization/isOrgRoleCodeSole/${name}`)
  },
  editAppOrg(param) {
    return http.POST(Global.addressip + `/api/Organization/EditOrgRole`, param)
  },
  deleteOrgRole(param) {
    return http.POST(Global.addressip + `/api/Organization/DelOrgRoles`, param)
  },
  addBatchRoleUser(param) {
    return http.POST(Global.addressip + `/api/Organization/AddBatchRoleUsers`, param)
  },
  delRoleUser(objectId, param) {
    return http.POST(Global.addressip + `/api/Organization/DelRoleUser/${objectId}`, param)
  },
  updateAppPermission(param) {
    return http.POST(Global.addressip + `/api/App/UpdateAppPermission`, param)
  },
  // 获取应用菜单
  getAppActiveMenuByCode(appCode) {
    return http.GET(Global.addressip + `/api/app/GetAppActiveMenuByCode/${appCode || ''}`)
  },
  // 获取应用信息
  getAppInfoByCode(appCode) {
    return http.GET(Global.addressip + `/api/App/GetAppInfoByCode/${appCode || ''}`)
  },
  // // 根据权限获取应用信息
  // getAppInfoByRole(appCode) {
  //   return http.GET(`api/App/GetAppInfoByRole/${appCode || ''}`)
  // },
  // 应用是否存在首页
  existAppHomeGridster(appCode) {
    return http.GET(Global.addressip + `/api/Site/ExistAppHomeGridster/${appCode || ''}`)
  },
  // 获取应用菜单项布局
  getAppItemView(appItemCode) {
    return http.GET(Global.addressip + `/api/app/GetAppItemView/${appItemCode || ''}`)
  },
  /**
     * 获取系统菜单
     * @param {string} dataType
     * @param {boolean} showSubTable
     * @param {boolean} showEmptyChild
     * @param {boolean} showOwnerApp
     */
  getAllAppActiveMenu(
    dataType,
    showSubTable,
    showEmptyChild,
    showOwnerApp,
    formDataSource,
    keyWord = null
  ) {
    if (formDataSource == undefined) formDataSource = false
    let api = Global.addressip + `/api/app/GetAllActiveWorkflowMenu/${dataType}/${showSubTable}/${showEmptyChild}/${showOwnerApp}/${formDataSource}`
    if (!IsNull(keyWord)) {
      api += `?keyWord=${keyWord}`
    }
    return http.GET(api)
  },
  // 获取树形控件默认值
  getAppItemRoot(appitemcode) {
    return http.GET(Global.addressip + `/api/app/GetAppItemRoot/${appitemcode}`)
  },
  // 获取存储过程
  getProcedureSourceList() {
    return http.GET(Global.addressip + `/api/DataSource/GetProcedureSourceList/`)
  },
  publishAppMenu(formCode, isPublished) {
    return http.GET(Global.addressip + `/api/APP/PublishAppMenu/${formCode}/${isPublished}`)
  },
  // 获取应用菜单
  getAppFunctionItems(appCode) {
    return http.GET(Global.addressip + `/api/APP/GetAppFunctionItems/${appCode}`)
  },
  // 检查关联引用
  checkRefAppData(functionCodes) {
    return http.POST(Global.addressip + `/api/APP/CheckRefAppData`, functionCodes)
  },
  // 检查关联引用
  checkRefAppDataByFile(file) {
    return http.HttpFileUpload(Global.addressip + `/api/APP/CheckRefAppDataByFile`, file)
  },
  checkAppExist(file) {
    return http.HttpFileUpload(Global.addressip + `/api/APP/CheckAppExist`, file)
  },
  exportApp(functionCodes) {
    return http.POST(Global.addressip + `/api/APP/ExportApp`, functionCodes, 'blob')
  },
  // 上传导入子表文件
  importApp(file) {
    return http.HttpFileUpload(Global.addressip + `/api/APP/ImportApp`, file)
  },
  getExportProgressPercentage(appCode) {
    return http.GET(Global.addressip + `/api/APP/GetExportProgressPercentage/${appCode}`)
  },
  setExportProgressPercentage(appCode) {
    return http.GET(Global.addressip + `/api/APP/SetExportProgressPercentage/${appCode}`)
  },
  getImportProgressPercentage(file) {
    return http.HttpFileUpload(Global.addressip + `/api/APP/GetImportProgressPercentage`, file)
  },
  setImportProgressPercentage(file) {
    return http.HttpFileUpload(Global.addressip + `/api/APP/SetImportProgressPercentage`, file)
  },
  isMenuRole(appCode, appItemCode) {
    return http.GET(Global.addressip + `/api/APP/IsMenuRole/${appCode}/${appItemCode}`)
  },
  isDesignForm(appCode) {
    return http.GET(Global.addressip + `/api/APP/IsDesignForm/${appCode}`)
  },
  getUserAppPermission(appCode, userId) {
    return http.GET(Global.addressip + `/api/APP/GetUserAppPermission/${appCode}/${userId}`)
  },
  getAppItemPermissions(appCode, appItemCode, userId) {
    return http.GET(Global.addressip + `/api/APP/GetUserButtonPermissions/${appCode}/${appItemCode}/${userId}`)
  }
}
